package com.zp.springcloud.controller;

import com.zp.springcloud.entiies.CommonResult;
import com.zp.springcloud.entiies.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
public class OrderController {
    public static final String PAYMENt_URL = ("http://localhost:8001");

    @Autowired
    RestTemplate restTemplate;

//    @GetMapping("/consumer/payment/create")//因为是消费者，用浏览器操作，所以只是读的操作 浏览器只支持get请求。
//    public CommonResult<Payment> creat(Payment payment) {
//        log.info("插入的数据" + payment);
//        return restTemplate.postForObject(PAYMENt_URL + "/payment/create", payment, CommonResult.class);
//    }
@GetMapping("/consumer/payment/create")
public CommonResult<Payment> create( Payment payment){
    log.info("********插入的数据：" + payment);
    //postForObject分别有三个参数：请求地址，请求参数，返回的对象类型
    return restTemplate.postForObject(PAYMENt_URL + "/payment/create", payment, CommonResult.class);
}


    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") long id) {
        log.info("id"+id);
        return restTemplate.getForObject(PAYMENt_URL + "/payment/get/" + id, CommonResult.class);
    }


}
